<template>
	<view style="padding: 40rpx;">
		<u--form labelPosition="left" labelWidth="90">
			<u-form-item label="类型" borderBottom ref="item1">
				<u-radio-group v-model="model.level_id" placement="column">
					<view style="display: flex;flex-wrap: wrap;">
						<u-radio :customStyle="{marginLeft: '8px'}" activeColor="#5990FF" v-for="(item, index) in radiolist" :key="index"
							:label="item.name" :name="item.id">
						</u-radio>
					</view>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="账号" borderBottom ref="item1">
				<u--input :disabled="isDisabled" v-model="model.mobile" type="number" placeholder="请输入账号" border="none"></u--input>
			</u-form-item>
			<u-form-item label="分润比例(%)" borderBottom ref="item1">
				<view style="width: 100%;">
					<u-slider inactiveColor="#5990FF" showValue activeColor="#5990FF"  v-model="model.bouns_rebate"></u-slider>
				</view>
			</u-form-item>
		</u--form>
		<button class="add-btn" @click="confirm()" style="background-color: #5990FF !important;color: #FFFFFF;margin-top: 150rpx;">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					mobile: '',
					level_id: '',
					bouns_rebate: 0
				},
				// 类型列表
				radiolist: [],
				isDisabled:false
			};
		},
		onLoad(option) {
			if(option.id){
				this.isDisabled = true
				this.id = option.id
				this.titleName = option.name
				uni.setNavigationBarTitle({
					title: this.titleName
				})
			}
			this.init()
		},
		methods: {
			async init() {
				await this.$fun.ajax.post('/user/level1Info', {}).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.radiolist = res.data
						if(this.id){
							this.$fun.ajax.post('/user/proxyInfo', {id:this.id}).then(res1 => {
								if (res1.code == 1) {
									this.model.level_id = res1.data.level1_id
									this.model.mobile = res1.data.mobile
									this.model.bouns_rebate = res1.data.bouns_rebate
								}
							})
						}
					}
				})
			},
			confirm(){
				let prams = {
					...this.model
				}
				console.log(prams)
				if(!prams.mobile){
					this.$fun.msg('请输入账号')
					return
				}
				if(this.id){
					prams.id = this.id
				}
				
				this.$fun.ajax.post('/user/upgrade',{...prams}).then(res=>{
					if(res.code==1){
						this.$fun.msg(res.msg)
						this.$fun.jump('',4,1200)
					}
				})
			}
		}
	};
</script>
